swadhinbiswas # Changelog · 1/21/2026
0c9b918
24 lines · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import type { APIRoute } from "astro";

/**
 * Redirect /owner/repo.git to /owner/repo
 * This handles the case when a user visits the .git URL directly in a browser
 */
export const GET: APIRoute = async ({ params, redirect }) => {
    const { owner, repo } = params;

    if (!owner || !repo) {
        return new Response("Not Found", { status: 404 });
    }

    // Remove .git suffix from repo name if present
    const repoName = repo.endsWith(".git") ? repo.slice(0, -4) : repo;

    return redirect(`/${owner}/${repoName}`, 302);
};

// Also handle POST for git operations that come without a path
export const POST: APIRoute = async ({ params }) => {
    return new Response("Bad Request", { status: 400 });
};